package com.century.sjt.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.util.Constant;

/**
 * Created by 炳基 on 2016/8/12.
 */
public class MyActivity extends BaseActivity {
    private LinearLayout show_me_zhxx, show_me_qb, show_me_sz, show_me_yqm;//show_me_qrr;
    private LinearLayout llMyOrder;
    private ImageView ciHeadimage;
    private TextView tvNickName;
    private String isShop, shopId;
    //private LinearLayout show_me_commodit;
    //private View show_view_commodit;
    //private ImageView img1, img2, img3, img4, img5;
    //private List<ImageView> imgList = new ArrayList<>();
    private LinearLayout left_layout;
    private TextView left_icon, right_icon2, purse_tv, invite_tv, order_tv,center_tv_icon;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_myactivity);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//软键盘设置
        initView();
        initEvent();
    }

    @Override
    public void onResume() {
        super.onResume();
        //  获取头像实例
        SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
        String image = mainSharedPreferences.getString("image", "");
        String nickName = mainSharedPreferences.getString("nickName", "");
        isShop = mainSharedPreferences.getString("isShop", "");
        if (!"".equals(image)) {
            Glide.with(MyActivity.this).load(Constant.ImageHost_Big + image).into(ciHeadimage);
        }
        if ("1".equals(isShop)) {
            shopId = mainSharedPreferences.getString("shopId", "");
            int shopLevel = mainSharedPreferences.getInt("shopLevel", 0);
//            if (shopLevel > 0) {
//                if (shopLevel > 5) {
//                    for (int i = 0; i < 5; i++) {
//                        imgList.get(i).setVisibility(View.VISIBLE);
//                        imgList.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.diamond_fg2x));
//                        //闪烁
//                        AlphaAnimation alphaAnimation1 = new AlphaAnimation(0.1f, 1.0f);
//                        alphaAnimation1.setDuration(1000);
//                        alphaAnimation1.setRepeatCount(Animation.INFINITE);
//                        alphaAnimation1.setRepeatMode(Animation.REVERSE);
//                        imgList.get(i).setAnimation(alphaAnimation1);
//                        alphaAnimation1.start();
//                    }
//                } else {
//                    for (int i = 0; i < shopLevel; i++) {
//                        imgList.get(i).setVisibility(View.VISIBLE);
//                        imgList.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.diamondw2x));
//                    }
//                }
//            }
        } else {
            int level = mainSharedPreferences.getInt("level", 0);
//            if (level > 5) {
//                for (int i = 0; i < 5; i++) {
//                    imgList.get(i).setVisibility(View.VISIBLE);
//                    imgList.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.star_fg2x));
//                    //闪烁
//                    AlphaAnimation alphaAnimation1 = new AlphaAnimation(0.1f, 1.0f);
//                    alphaAnimation1.setDuration(1000);
//                    alphaAnimation1.setRepeatCount(Animation.INFINITE);
//                    alphaAnimation1.setRepeatMode(Animation.REVERSE);
//                    imgList.get(i).setAnimation(alphaAnimation1);
//                    alphaAnimation1.start();
//                }
//            } else {
//                for (int i = 0; i < level; i++) {
//                    imgList.get(i).setVisibility(View.VISIBLE);
//                    imgList.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.star2x));
//                }
            }
        tvNickName.setText(nickName);
        }


    @Override
    protected void initView() {
        SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);

        left_icon = (TextView) findViewById(R.id.left_icon);
        right_icon2 = (TextView) findViewById(R.id.right_icon2);
        purse_tv = (TextView) findViewById(R.id.purse_tv);
        invite_tv = (TextView) findViewById(R.id.invite_tv);
        order_tv = (TextView) findViewById(R.id.order_tv);
//        center_tv_icon= (TextView) findViewById(R.id.center_tv_icon);
        Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont.ttf");
        left_icon.setTypeface(iconfont);
        right_icon2.setTypeface(iconfont);
        purse_tv.setTypeface(iconfont);
        invite_tv.setTypeface(iconfont);
        order_tv.setTypeface(iconfont);
//        center_tv_icon.setTypeface(iconfont);
        ciHeadimage = (ImageView) findViewById(R.id.profile_image);
        tvNickName = (TextView) findViewById(R.id.tv_nick_name);
        show_me_zhxx = (LinearLayout) findViewById(R.id.me_show_zhxx);
        show_me_qb = (LinearLayout) findViewById(R.id.me_show_qb);
        show_me_sz = (LinearLayout) findViewById(R.id.me_show_sz);
        show_me_yqm = (LinearLayout) findViewById(R.id.me_show_yqm);
       // show_me_qrr= (LinearLayout) findViewById(R.id.rightlayout_icon1);
        llMyOrder = (LinearLayout) findViewById(R.id.ll_my_order);
        left_layout = (LinearLayout) findViewById(R.id.left_layout);


//        img1 = (ImageView) findViewById(R.id.img_1);
//        img2 = (ImageView) findViewById(R.id.img_2);
//        img3 = (ImageView) findViewById(R.id.img_3);
//        img4 = (ImageView) findViewById(R.id.img_4);
//        img5 = (ImageView) findViewById(R.id.img_5);
//
//        imgList.add(img1);
//        imgList.add(img2);
//        imgList.add(img3);
//        imgList.add(img4);
//        imgList.add(img5);




    }

    @Override
    protected void initEvent() {
        show_me_zhxx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MyActivity.this, MydataActivity.class);
                startActivity(intent);
            }
        });

        //我的订单
        llMyOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断是商家、分店、还是用户
                SharedPreferences mainSharedPreferences = getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String isMerchant = mainSharedPreferences.getString("isMerchant", "");
                String isShop = mainSharedPreferences.getString("isShop", "");

                if(isMerchant.equals("0")&isShop.equals("0")){
                    //用户
                    startActivity(MyActivity.this, MyOrderActivity.class);
                }else{
                    //商家、分店
                   startActivity(MyActivity.this, MerchantOrderActivity.class);
                }

            }
        });
        if ("1".equals(isShop)) {

        }

        show_me_qb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MyActivity.this, WalletActivity.class);
                startActivity(intent);
            }
        });

        show_me_sz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MyActivity.this, SettingActivity.class);
                startActivity(intent);
            }
        });

        show_me_yqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MyActivity.this, MyInviteNumberActivity.class);
                startActivity(intent);

            }
        });
//        show_me_qrr.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(MyActivity.this,QRRecordCodeScanActivity.class);
//            }
//        });
        left_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {

    }
}
